import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_video/app_theme.dart';
import 'package:flutter_video/custom/search_bar.dart';
import 'package:flutter_video/home/recommend.dart';
import 'package:flutter_video/custom/custom_tab_bar1.dart' as Custom;

import '../custom/indicator.dart';

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomePageState();
  }
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  TabController _tabController; //需要定义一个Controller
  List tabs = ["推荐", "电视剧", "电影", "动漫", "综艺", "电视剧", "电影23", "动漫", "综艺"];

  @override
  void initState() {
    super.initState();
    // 创建Controller
    _tabController = TabController(length: tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: AppTheme.white,
        appBar: AppBar(
          toolbarHeight: 74,
          backgroundColor: AppTheme.white,
          elevation: 0.0,
          titleSpacing: 0,
          leading: Container(
              alignment: Alignment.center,
              child: SvgPicture.asset(
                "assets/img/logo.svg",
                height: 24,
              )),
          title: Container(
            child: SearchStaticBar(
              hint: "点击搜索",
              margin: EdgeInsets.only(top: 0.0, bottom: 0.0),
              padding: EdgeInsets.only(top: 6.0, bottom: 6.0,left: 10),
            ),
          ),
          actions: <Widget>[
            IconButton(
              icon: const Icon(
                IconData(0xe9a8, fontFamily: 'AntIcons'),
                color: Color.fromRGBO(56, 59, 64, 1),
              ),
              onPressed: () {},
            ),
            IconButton(
              icon: const Icon(
                IconData(0xe612, fontFamily: 'AntIcons'),
                color: Color.fromRGBO(56, 59, 64, 1),
              ),
              onPressed: () {},
            )
          ],
          bottom: PreferredSize(
            preferredSize: Size.fromHeight(34),
            child: Container(
              height: 34,
              child: Custom.TabBar(
                  controller: _tabController,
                  isScrollable: true,
                  tabs: tabs.map((e) => Tab(text: e)).toList(),
                  indicator: RoundUnderlineTabIndicator(
                      borderSide: BorderSide(
                    width: 4,
                    color: Colors.red,
                  )),
                  indicatorSize: Custom.TabBarIndicatorSize.label,
                  labelStyle: TextStyle(
                    fontSize: 16.0,
                    fontWeight: FontWeight.bold,
                  ),
                  unselectedLabelColor: Color.fromRGBO(166, 170, 182, 1),
                  unselectedLabelStyle: TextStyle(
                    fontSize: 16.0,
                    fontWeight: FontWeight.bold,
                  )),
            ),
          ),
        ),
        body: TabBarView(controller: _tabController, children: [
          RecommendPage(),
          Container(
              alignment: Alignment.center,
              child: new SvgPicture.asset(
                "assets/img/logo.svg",
                height: 20,
              )),
          Container(
              alignment: Alignment.center,
              child: Text(
                "推荐3",
                textScaleFactor: 3,
              )),
          Container(
              alignment: Alignment.center,
              child: Text(
                "推荐4",
                textScaleFactor: 3,
              )),
          Container(
              alignment: Alignment.center,
              child: Text(
                "推荐4",
                textScaleFactor: 3,
              )),
          Container(
              alignment: Alignment.center,
              child: Text(
                "推荐3",
                textScaleFactor: 3,
              )),
          Container(
              alignment: Alignment.center,
              child: Text(
                "推荐4",
                textScaleFactor: 3,
              )),
          Container(
              alignment: Alignment.center,
              child: Text(
                "推荐4",
                textScaleFactor: 3,
              )),
          Container(
              alignment: Alignment.center,
              child: Text(
                "推荐4",
                textScaleFactor: 3,
              ))
        ]));
  }
}
